<template>
	<view class="container">
		<view class="header">
			<view class="arrow" @tap="$back()"><image src="../../static/images/arrow_left.png" mode="aspectFit"></image></view>
			<view class="tit f36 cfff">供应商({{SupplierList.length}})</view>
			<view class="btn" @tap="addOpen()"><image src="../../static/images/tb_more.png" mode="aspectFit"></image></view>
		</view>

		<view class="seach">
			<view class="seach-s" @confirm="confirm">
				<image src="../../static/images/tb_search.png" mode="" @confirm="confirm"></image>
				<input type="text" value="" placeholder="请输入供应商名称..." v-model="name" @confirm="confirm" confirm-type="search"/>
			</view>
		</view>

		<view class="supplierBox">
			<view class="supplier-item" v-for="(item,index) in SupplierList" :key="index" @tap="goDetail(item,item.supplier_id)">
				<view class="left">
					<view class="name f32 c333">{{item.name}}</view>
					<view class="money f30 c666">欠款应商款：{{item.debt}}</view>
					<view class="people f30 c666">负责人：{{item.contact=='' ? '无' :item.contact }}</view>
				</view>

				<view class="right"><view class="pay f30 cfff" @tap.stop="gopPay(item.supplier_id)">付款</view></view>
			</view>

	<!-- 暂无数据 -->
	<view class="ima" v-if="SupplierList.length == 0"><image src="../../static/slice/86438f8f6d0029f503d57efb448590f.png" mode="aspectFit"></image></view>
		</view>

		<!-- 新增弹窗 -->

		<view class="addBox" :class="showClass"  @tap="hideAdd">
			<view class="addCont" >
				<view class="add-item" @tap="$open('supplierAdd')">
					<view class="pic"><image src="../../static/images/add_custom.png" mode="aspectFit"></image></view>
					<view class="text f32 c666">新增供应商</view>
				</view>

				<view class="add-item">
					<view class="pic"><image src="../../static/images/icon_person.png" mode="aspectFit"></image></view>
					<view class="text f32 c666">通讯录导入</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			showClass:'',
			name:'',
			state:'',
			goodsList:[],
			SupplierList:[]
		};
	},
	onShow() {
		this.getSupplier()
		this.state=uni.getStorageSync('state')
		console.log(this.state)
	},
	methods:{
		addOpen(){
			this.showClass = 'show';
		},
		hideAdd(){
			setTimeout(() => {
				this.showClass = 'none';
			}, 200);
		},
		
		 getSupplier(){
			 let that=this;
			 that.$ajax('api/v1.supplier/index',{
				 
			 }).then(res=>{
				if(res.code==1){
					 that.SupplierList=that.goodsList=res.result.list
				}
			 }).catch(res=>{
				 that.$sToast(res.message)
			 })
		 },
		 confirm: function() {
		 	this.SupplierList = this.goodsList.filter(item => {
		 		return item.name == this.name;
		 	});
		 },
		 goDetail(item,id){
			 if(this.state==1){
				 uni.navigateTo({
				 	url:'./supplierBilling?item='+JSON.stringify(item)
				 })
				 uni.removeStorageSync('state')
			 }else{
				 uni.navigateTo({
				 	url:'./supplierDetails?id='+id
				 })
			 }
			 
		 },
		 gopPay(id){
			uni.navigateTo({
				url:'./supplierpayment?id='+id
			}) 
		 }
		
		
		
		
	}
};
</script>

<style lang="scss">
page {
	background-color: #f5f5f5;
}
.header {
	display: flex;
	flex-direction: row;
	align-items: center;
	justify-content: space-between;
	background-color: #249af6;
	padding: 40upx 30upx 10upx 30upx;

	.arrow {
		image {
			width: 20upx;
			height: 40upx;
		}
	}

	.btn {
		image {
			width: 44upx;
			height: 44px;
		}
	}
}
.seach {
	width: 100%;
	background-color: #249af6;
	margin: auto;
	display: flex;
	flex: 1;
	justify-content: center;
	padding: 0 30rpx 25upx 30rpx;
	box-sizing: border-box;

	.seach-s {
		width: 100%;
		height: 60rpx;
		line-height: 60rpx;
		font-size: 28upx;
		color: #999;
		background: rgba(255, 255, 255, 1);
		border-radius: 99999rpx;
		padding-left: 27rpx;
		display: flex;
		box-sizing: border-box;
		input {
			padding-top: 10rpx;
			border-style: none;
			font-size: 28upx;
			color: #999;
		}
		image {
			width: 31rpx;
			height: 28rpx;
			margin-top: 15rpx;
			margin-right: 20rpx;
		}
	}
}
.supplierBox {
	.supplier-item {
		display: flex;
		flex-direction: row;
		justify-content: space-between;
		background-color: $white-background;
		padding: 40rpx 30rpx;
		margin-top: 30rpx;
		.left {
			width: 70%;
			.name {
				overflow: hidden;
				text-overflow: ellipsis;
				white-space: nowrap;
			}
			.money {
				margin: 10rpx 0;
			}
		}
		.right {
			width: 105rpx;
			.pay {
				width: 105rpx;
				height: 65rpx;
				line-height: 65rpx;
				background-color: #249af6;
				border-radius: 10rpx;
				text-align: center;
				margin-top: 40rpx;
			}
		}
	}
}
.addBox {
	width: 100%;
	height: 100%;
	position: fixed;
	left: 0;
	right: 0;
	top: 0;
	bottom: 0;
	background: rgba(0, 0, 0, 0.5);
	display: none;
	&.show{
		display: block;
	}
	&.hide{
		display: none;
	}
	.addCont {
		background-color: $white-background;
		border-radius: 10rpx;
		width: 300rpx;
		position: absolute;
		top: 150rpx;
		right: 30rpx;
		.add-item {
			display: flex;
			flex-direction: row;
			align-items: center;
			border-bottom: 2rpx #eeeeee solid;
			padding-bottom: 35rpx;
			margin-top: 35rpx;
			.pic {
				image {
					width: 43rpx;
					height: 44rpx;
					margin-right: 25rpx;
					vertical-align: middle;
					margin-left: 35rpx;
				}
			}
		}
	}
}
.ima {
	display: flex;
	justify-content: center;
	align-items: center;
	margin-top: 227rpx;
	image {
		width: 370upx;
		height: 390upx;
	}
}
</style>
